<html>
<head>
<meta charset="utf-8">
<meta name="_csrf" th:content="${_csrf.token}" />
<meta name="_csrf_header" th:content="${_csrf.headerName}" />
<style>
body {
	margin: 0;
	padding: 0;
	word-wrap: break-word;
}
</style>
</head>
<body>
	<div id="article-content">
	<div id="preview" ></div>
	</div>
	<script type="text/javascript" th:src="@{/static/jquery/jquery.min.js}"></script>
	<script type="text/javascript" th:src="@{/static/prettify/prettify.js}"></script>
	<script type="text/javascript">
	$(function(){
		$("#preview").on("click","a",function(e){
		    e.preventDefault();
		});
		
	});
	
	function renderCode(){
		var p = false;
		$("pre").each(function(){
			var me = $(this);
			if(me.hasClass('prettyprint prettyprinted'))
				return true;
			if(me.find('code').length == 0)
				 return true;
			else{
				p = true;
				me.addClass("prettyprint");
			}
		});
		if(p)
			prettyPrint();
	}
	
	function setPreview(preview){
		$("#preview").html(preview);
		renderCode();
	}
	
	function setStyle(style){
		//清除所有样式
		$("head").find('link[type="text/css"]').remove();
		$("head").find('style').remove();
		var csses = style.csses.split('\n');
		if(csses.length > 0){
			for(var i=0;i<csses.length;i++){
				var css = $.trim(csses[i]);
				$("head").append($("<link rel='stylesheet' href='"+css+"' type='text/css' media='screen' />"));
			}
		}
		if($.trim(style.styles) != ""){
			$('head').append('<style>'+style.styles+'</style>')
		}
		$("#article-content").removeClass();
		if(style.preview != "" ){
			$("#article-content").addClass(style.preview);
		}
	}
	
	</script>
</body>
</html>